using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Decisions.HL7.Message;
using DecisionsFramework;

namespace Decisions.HL7.Message
{
    public class RepeatPatternAttribute:RuleAttribute
    {
        private Dictionary<HL7Version, string[]> validVersionCodes = new Dictionary<HL7Version, string[]>();
        private Dictionary<HL7Version, string[]> validVersionDescriptions = new Dictionary<HL7Version, string[]>();
        private Dictionary<HL7Version, HL7TableType> tableVersionTypes = new Dictionary<HL7Version, HL7TableType>();

        public RepeatPatternAttribute()
        {
            // init the values for table version types
						tableVersionTypes[HL7Version.v23] = HL7TableType.User;
						tableVersionTypes[HL7Version.v231] = HL7TableType.User;
						tableVersionTypes[HL7Version.v24] = HL7TableType.User;
						tableVersionTypes[HL7Version.v25] = HL7TableType.User;
						tableVersionTypes[HL7Version.v251] = HL7TableType.User;
						tableVersionTypes[HL7Version.v26] = HL7TableType.User;
						tableVersionTypes[HL7Version.v27] = HL7TableType.User;
			
            
			// init the values for version codes
						validVersionCodes[HL7Version.v23] = new string[]{""};
						validVersionCodes[HL7Version.v231] = new string[]{""};
						validVersionCodes[HL7Version.v24] = new string[]{"Q<integer>S","Q<integer>M","Q<integer>H","Q<integer>D","Q<integer>W","Q<integer>L","Q<integer>J<day#>","BID","TID","QID","xID","QAM","QSHIFT","QOD","QHS","QPM","C","U <spec>","PRN","PRNxxx","Once","Meal Related Timings","A","P","I","M","D","V"};
						validVersionCodes[HL7Version.v25] = new string[]{"Q<integer>S","Q<integer>M","Q<integer>H","Q<integer>D","Q<integer>W","Q<integer>L","Q<integer>J<day#>","BID","TID","QID","xID","QAM","QSHIFT","QOD","QHS","QPM","C","U <spec>","PRN","PRNxxx","Once","Meal Related Timings","A","P","I","M","D","V"};
						validVersionCodes[HL7Version.v251] = new string[]{"Q<integer>S","Q<integer>M","Q<integer>H","Q<integer>D","Q<integer>W","Q<integer>L","Q<integer>J<day#>","BID","TID","QID","xID","QAM","QSHIFT","QOD","QHS","QPM","C","U <spec>","PRN","PRNxxx","Once","Meal Related Timings","A","P","I","M","D","V"};
						validVersionCodes[HL7Version.v26] = new string[]{"Q<integer>S","Q<integer>M","Q<integer>H","Q<integer>D","Q<integer>W","Q<integer>L","Q<integer>J<day#>","BID","TID","QID","xID","QAM","QSHIFT","QOD","QHS","QPM","C","U <spec>","PRN","PRNxxx","Once","Meal Related Timings","A","P","I","M","D","V"};
						validVersionCodes[HL7Version.v27] = new string[]{"Q<integer>S","Q<integer>M","Q<integer>H","Q<integer>D","Q<integer>W","Q<integer>L","Q<integer>J<day#>","BID","TID","QID","xID","QAM","QSHIFT","QOD","QHS","QPM","C","U <spec>","PRN","PRNxxx","Once","Meal Related Timings","A","P","I","M","D","V"};
			
			// init the values for version descriptions
						validVersionDescriptions[HL7Version.v23] = new string[]{""};
						validVersionDescriptions[HL7Version.v231] = new string[]{""};
						validVersionDescriptions[HL7Version.v24] = new string[]{"every <integer> seconds","every <integer> minutes","every <integer> hours","every <integer> days","every <integer> weeks","every <integer> months (Lunar cycle)","repeats on a particular day of the week, from the French jour (day).  If <integer> is missing, the repeat rate is assumed to be 1.  Day numbers are counted from 1=Monday to 7=Sunday.  So Q2J2 means every second Tuesday; Q1J6 means every Saturday.","twice a day at institution-specified times (e.g., 9AM-4PM)","three times a day at institution-specified times (e.g., 9AM-4PM-9PM)","four times a day at institution-specified times (e.g., 9AM-11AM-4PM-9PM)","\"X\" times per day at institution-specified times, where X is a numeral 5 or greater.  E.g., 5ID=five times per day; 8ID=8 times per day","in the morning at institution-specified time","during each of three eight-hour shifts at institution-specified times","every other day (same as Q2D)","every day before the hour of sleep","in the evening at institution-specified time","service is provided continuously between start time and stop time","for future use, where <spec> is an interval specification as defined by the UNIX cron specification.","given as needed","where xxx is some frequency code (e.g., PRNQ6H); given as needed over the frequency period.","one time only.  This is also the default when this component is null.","<timing>C (\"cum\")<meal>","Ante (before)","Post (after)","Inter (e.g., between this meal and the next, between dinner and sleep","Cibus Matutinus (breakfast)","Cibus Diurnus (lunch)","Cibus Vespertinus (dinner)"};
						validVersionDescriptions[HL7Version.v25] = new string[]{"every <integer> seconds","every <integer> minutes","every <integer> hours","every <integer> days","every <integer> weeks","every <integer> months (Lunar cycle)","repeats on a particular day of the week,","twice a day at institution-specified times","three times a day at institution-specified times","four times a day at institution-specified times","\"X\" times per day at institution-specified times, where X is a numeral 5 or greater.","in the morning at institution-specified time","during each of three eight-hour shifts at institution-specified times","every other day","every day before the hour of sleep","in the evening at institution-specified time","service is provided continuously between start time and stop time","for future use, where <spec> is an interval specification as defined by the UNIX cron specification.","given as needed","where xxx is some frequency code","one time only.","<timing>C (\"cum\")<meal>","Ante (before)","Post (after)","Inter","Cibus Matutinus (breakfast)","Cibus Diurnus (lunch)","Cibus Vespertinus (dinner)"};
						validVersionDescriptions[HL7Version.v251] = new string[]{"every <integer> seconds","every <integer> minutes","every <integer> hours","every <integer> days","every <integer> weeks","every <integer> months (Lunar cycle)","repeats on a particular day of the week,","twice a day at institution-specified times","three times a day at institution-specified times","four times a day at institution-specified times","âXâ times per day at institution-specified times, where X is a numeral 5 or greater.","in the morning at institution-specified time","during each of three eight-hour shifts at institution-specified times","every other day","every day before the hour of sleep","in the evening at institution-specified time","service is provided continuously between start time and stop time","for future use, where <spec> is an interval specification as defined by the UNIX cron specification.","given as needed","where xxx is some frequency code","one time only.","<timing>C (âcumâ)<meal>","Ante (before)","Post (after)","Inter","Cibus Matutinus (breakfast)","Cibus Diurnus (lunch)","Cibus Vespertinus (dinner)"};
						validVersionDescriptions[HL7Version.v26] = new string[]{"every <integer> seconds","every <integer> minutes","every <integer> hours","every <integer> days","every <integer> weeks","every <integer> months (Lunar cycle)","repeats on a particular day of the week,","twice a day at institution-specified times","three times a day at institution-specified times","four times a day at institution-specified times","\"X\" times per day at institution-specified times, where X is a numeral 5 or greater.","in the morning at institution-specified time","during each of three eight-hour shifts at institution-specified times","every other day","every day before the hour of sleep","in the evening at institution-specified time","service is provided continuously between start time and stop time","for future use, where <spec> is an interval specification as defined by the UNIX cron specification.","given as needed","where xxx is some frequency code","one time only.","<timing>C (\"cum\")<meal>","Ante (before)","Post (after)","Inter","Cibus Matutinus (breakfast)","Cibus Diurnus (lunch)","Cibus Vespertinus (dinner)"};
						validVersionDescriptions[HL7Version.v27] = new string[]{"every <integer> seconds","every <integer> minutes","every <integer> hours","every <integer> days","every <integer> weeks","every <integer> months (Lunar cycle)","repeats on a particular day of the week,","twice a day at institution-specified times","three times a day at institution-specified times","four times a day at institution-specified times","\"X\" times per day at institution-specified times, where X is a numeral 5 or greater.","in the morning at institution-specified time","during each of three eight-hour shifts at institution-specified times","every other day","every day before the hour of sleep","in the evening at institution-specified time","service is provided continuously between start time and stop time","for future use, where <spec> is an interval specification as defined by the UNIX cron specification.","given as needed","where xxx is some frequency code","one time only.","<timing>C (\"cum\")<meal>","Ante (before)","Post (after)","Inter","Cibus Matutinus (breakfast)","Cibus Diurnus (lunch)","Cibus Vespertinus (dinner)"};
			            

        }

        
        public override ValidationIssue[] RunRule(string name, object owningObject, object value)
        {
            //todo: check if the value is valid in the current version
            //if the value is not valid in the current version, add it as a validation issue


            return new ValidationIssue[0];
        }
    }
}
